
package com.sausageking.client.consumer.gin;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.inject.Inject;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import com.google.inject.name.Names;
import com.sausageking.client.consumer.mvp.MobileAppPlaceFactory;
import com.sausageking.client.consumer.mvp.MobileAppPlaceHistoryMapper;
import com.sausageking.client.consumer.place.MobileDealPlace;
import com.sausageking.client.consumer.ui.MobileDealView;
import com.sausageking.client.consumer.ui.MobileDealViewImpl;

public class MobileGinModule extends BaseGinModule {

  @Override
  void addAppSpecficicConfig() {

    // bind the views
    bind(MobileDealView.class).to(MobileDealViewImpl.class);

    // bind places
    bind(Place.class).annotatedWith(Names.named("default")).to(
        MobileDealPlace.class);

  }

  @Inject
  @Singleton
  @Provides
  MobileAppPlaceHistoryMapper provideMobileAppPlaceHistoryMapper(
      MobileAppPlaceFactory factory) {
    MobileAppPlaceHistoryMapper historyMapper = GWT
        .create(MobileAppPlaceHistoryMapper.class);
    historyMapper.setFactory(factory);
    return historyMapper;
  }

  @SuppressWarnings("deprecation")
  @Inject
  @Singleton
  @Provides
  PlaceHistoryHandler providePlaceHistoryHandler(
      MobileAppPlaceHistoryMapper historyMapper, PlaceController placeController,
      EventBus eventBus, @Named("default") Place defaultPlace) {
    PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
    historyHandler.register(placeController, eventBus, defaultPlace);
    return historyHandler;
  }

}
